package com.liuhx.service.impl;

import com.liuhx.entity.ModelsEntity;
import com.liuhx.mapper.ModelsMapper;
import com.liuhx.service.ModelsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by liuhx on 2017/7/13.
 */
@Service
public class ModelsServiceImpl implements ModelsService{
    @Resource
    ModelsMapper modelsMapper;
    @Override
    public void insert(List<ModelsEntity> modelsEntityList) {
        int brandId = modelsEntityList.get(0).getBrandId();
        List<ModelsEntity> list = modelsMapper.findAllModels(brandId);
        modelsEntityList.removeAll(list);
        if(modelsEntityList.size()>0)
        {
            modelsMapper.insertModels(modelsEntityList);
        }
    }

    @Override
    public List<ModelsEntity> findById(int brandId) {
        return modelsMapper.findAllModelsHaveId(brandId);
    }
}
